<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">

		<link rel="stylesheet" type="text/css" href="../js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="../vendor/jquery/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="../js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
		
		
		<script>
		$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
			$.ajaxSetup({
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				}
			});
		});
	</script>
		<script type="text/javascript">
			//查询加模糊查询
			$(function() {
				$("#table").bootstrapTable({   
					type: "get",
					url: "http://127.0.0.1:8099/ksgetall", 
					pagesize: "3", 
					queryParams: queryParams,
					columns: [{
						field: "did",
						title: "序号",
						align: "center",
					}, {
						field: "department_name",
						title: "科室名称",
						align: "center",
					}, {
						field: "department_number",
						title: "科室序号",
						align: "center",
					}, {

						title: '操作',
						align: 'center',
						formatter: function(value, row, index) {
							return '<button type="button"  onclick="ksxgnz(' + row.did + ')"  data-toggle="modal"  data-target="#myModa2" class="btn btn-primary">编辑</button>' + '<button type="button"  onclick="ksdele(' + row.did + ')"  class="btn btn-default">删除</button>'

						}
					}]

				})

				$("#tjia").click(function() {
					$("#adddepartment_name").val("")
				})


				/*添加*/
				$("#Ksadd").click(function() { 
					alert(1)
					$.ajax({
						type: "post",
						url: "http://127.0.0.1:8099/Ksadd",
						data: $("#ksadd").serialize(),
						success: function(data) {
							if(data == "yes") {
								$("#myModal").modal("hide");
								$("#table").bootstrapTable("refresh");
							}else{
								$("#myModal").modal("hide")
						        $("#iii").modal("show")
							}
						}
					});
				})
 
 /*修改*/
        $("#ksxg").click(function () {
        	
        	$.ajax({
        		type:"post",
        		url:"http://127.0.0.1:8099/ksxgai",
        		data:$("#ksxgai").serialize(),
        		success:function (data) {
        			
        		$("#myModa2").modal("hide")
        		$("table").bootstrapTable("refresh")
        		}
        	});
        })
 
 

				/*模糊查询 */
				    $("#mohu").click(function() {
					$("#table").bootstrapTable("refresh");
				})
			})
			 
		
			//删除                                                                
			function ksdele(did) {
				
				$.ajax({
					type: "post",
					url: "http://127.0.0.1:8099/ksdele/" + did,
					dataType: "json",
					success: function(data) {
						$("table").bootstrapTable("refresh")
					}
				});
			}
			
			
		
			//修改拿值 
			function ksxgnz(did) {
				$.ajax({
					type: "get",
					url: "http://127.0.0.1:8099/ksxgnz/" + did,
					dataType: "json",
					success: function(data) {
						$("#namexgnz").val(data.department_name)
						$("#did1").val(data.did)
					}
				})
			} 
		
			function queryParams() {
				return {
					'department_name': $("#mhname").val(),
				}
			}
		</script>
		
	</head>
		
	<body>
		
		<table width="100%" height="50" border="0">
		
			<tr bgcolor="#F6F6F6">
				<td width="100" align="right">科室名称：</td>
				<td width="130" align="right">
					<form class="form-inline">
						<div class="form-group">
							<input type="text" class="form-control" id="mhname" placeholder="请输入科室名称">
						</div>
		
					</form>
				</td>
				<td width="20"></td>
				<td>
					<form class="form-inline">
		
						<button type="button" class="btn btn-primary" id="mohu">查询</button>
					</form>
				</td>
				<td></td>
				<td></td>
				<td>
					<div style="text-align:right"><button id="tjia" type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">添加</button>
					</div>
					<!-- Modal -->
					<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
						<div class="modal-dialog" role="document" style="width: 390px">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
									<h4 class="modal-title" id="myModalLabel">添加科室</h4>
								</div>
								<div class="modal-body">
		
									<form class="form-inline" id="ksadd">
										<div class="form-group">
											<table width="100%" cellspacing="" cellpadding="">
		
												<tr>
													<td width="80"><label for="exampleInputName2">科室名称：</label></td>
													<td> <input type="text" class="form-control" id="adddepartment_name" name="department_name" placeholder="请输入科室名称"></td>
												</tr>
											</table>
		
										</div>
		
									</form>
		
								</div>
								<div class="modal-footer">
		
									<button type="button" id="Ksadd" class="btn btn-primary">保存</button>
								</div>
							</div>
						</div>
					</div>
				</td>
				<td width="30"></td>
			</tr>
		</table>
		
		<!--22222222222222222222222222222222222222222222222222222222222222222222222222-->
		
		<!-- Modal -->
		<div class="modal fade" id="myModa2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">编辑科室</h4>
					</div>
					<div class="modal-body">
		
						<form class="form-inline" id="ksxgai">
							<div class="form-group">
								<table width="100%" cellspacing="" cellpadding="">
		
									<input type="hidden" id="did1" name="did" />
									<tr>
										<td width="80"><label for="exampleInputName2">科室名称：</label></td>
										<td> <input type="text" class="form-control" id="namexgnz" name="department_name"></td>
									</tr>
        
								</table>
		
							</div>
                                  
						</form> 
		
					</div>
					<div class="modal-footer">
		
						<button type="button" id="ksxg" class="btn btn-primary" onclick="">保存</button>
					</div>
				</div>
			</div>
		</div>
		
		
		
		
		
		
		
		<div class="modal fade" tabindex="-1" role="dialog" id="iii" >
  <div class="modal-dialog" role="document" style="width: 200px">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
       
      </div>
      <div class="modal-body">
        <p>科室名称不能重复</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn- bg-primary" data-dismiss="modal">退出</button>
        
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



      <table id="table"></table>
	    </body>
	
</html>